var oschat = {
	version: "0.0.1"
};


var gui = require('nw.gui');

//Get the current window
var win = gui.Window.get();


oschat.win = (function(){
	return {
		init: function(){
			oschat.win.viewEventBind();
			oschat.win.winEventBind();
		},
		
		viewEventBind:function(){
			$('.login-btn').click(function(){
				var username = $("#username").val();
				var password = $("#password").val();
				if(username==""){
					$('.login-msg span').html('用户名不能为空！');
					$('.login-msg').show();
				}else{
					api.login(username, password, function(data){
						var result = data.result;
						if(result == "CONNECTION_FAIL"){
							$('.login-msg span').html('服务器连接失败！');
							$('.login-msg').show();
							return;
						}
						if(result.event == "LOGIN_SUCCESS"){
							win.window.location.href = "http://www.baidu.com";
						}else{
							$('.login-msg span').html('用户名或者密码错误！');
							$('.login-msg').show();
						}
					});
				}
			});
		},
		
		winEventBind : function(){
			win.on('resize',function(){
				alert(1);
			});
		}
	}
})();